package com.ipinyou.wordstatistics;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.LinkedHashSet;
import java.util.Set;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;

/**
 * 将xls去掉重复从新生成xls
 *
 */
public class App1 
{
    public static void main( String[] args ) throws Exception
    {
        Set<String> codeSet=new LinkedHashSet<String>();
        POIFSFileSystem fs=new POIFSFileSystem(new FileInputStream("/home/wangxiangnan/Book1.xls"));
        HSSFWorkbook wb=new HSSFWorkbook(fs);
        HSSFWorkbook wb2=new HSSFWorkbook();
        HSSFSheet sheet2=wb2.createSheet();
        int sn=wb.getNumberOfSheets();
        for(int i=0;i<sn;i++){
            HSSFSheet sheet1=wb.getSheetAt(i);
            int rn=sheet1.getLastRowNum();
            for(int r=0;r<=rn;r++){
                HSSFCell cell=sheet1.getRow(r).getCell(1);
                if(cell!=null){
                    codeSet.add(cell.getStringCellValue());
                }
            }
        }
        int rn2=0;
        for(String code:codeSet){
            sheet2.createRow(rn2).createCell(0).setCellValue(code);
            rn2++;
        }
        wb2.write(new FileOutputStream("/home/wangxiangnan/Book3.xls"));
    }
}
